﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TVDL4.DAO;
using TVDL4.VO;
namespace TVDL4.BUS
{
    class GiaiDoanBUS
    {
             private GiaiDoanDAO GiaiDoanDAO;
             /// <constructor>
            /// Constructor VatLieuBUS
            /// </constructor>
            public GiaiDoanBUS()
            {
                GiaiDoanDAO = new GiaiDoanDAO();
            }
            public GiaiDoanVO SetGiaiDoan(DataRow dr)
            {
                DataTable dataTable;
                GiaiDoanDetailVO GiaiDoandetailVO;
                GiaiDoanNguoiThucHienVO GiaiDoannguoithuchienVO;
                GiaiDoanVO GiaiDoanVO = new GiaiDoanVO();
                GiaiDoanVO.KeySL = dr["KEYSL"].ToString();
                GiaiDoanVO.TenGiaiDoan  = dr["TENGiaiDoan"].ToString();
                GiaiDoanVO.Hangmuc = dr["Hangmuc"].ToString();
                GiaiDoanVO.CongTrinh.KeySL = dr["KeyslCongTrinh"].ToString();
                GiaiDoanVO.CongTrinh.TenCongTrinh = dr["TENCONGTRINH"].ToString();
                GiaiDoanVO.CongTrinh.LoaiCongTrinh = dr["LOAICONGTRINH"].ToString();
                GiaiDoanVO.CongTrinh.HoanThanh = Convert.ToInt16(dr["HOANTHANH"]);
                GiaiDoanVO.ThoiGian = dr["THOIGIAN"].ToString();
                GiaiDoanVO.ThoiGianDen = dr["DENTHOIGIAN"].ToString();
                GiaiDoanVO.PhuTrach  = dr["PHUTRACH"].ToString();
                GiaiDoanVO.SlThiNghiem = Convert.ToInt32(dr["SLTHINGHIEM"]);
                GiaiDoanVO.SlThamChieu = Convert.ToInt32(dr["SLTHAMCHIEU"]);
                GiaiDoanVO.Dat_MT_Nguyendang = Convert.ToInt32(dr["DAT_MT_NGUYENDANG"]);
                GiaiDoanVO.Dat_MT_Roi = Convert.ToInt32(dr["DAT_MT_ROI"]);
                GiaiDoanVO.Dat_MT_Vatlieu = Convert.ToInt32(dr["DAT_MT_VATLIEU"]);
                GiaiDoanVO.Dat_MT_Doam = Convert.ToInt32(dr["DAT_MT_DOAM"]);
                GiaiDoanVO.Dat_MT_Damchat = Convert.ToInt32(dr["Dat_MT_Damchat"]);
                GiaiDoanVO.Dat_MB_Nguyendang = Convert.ToInt32(dr["DAT_MB_NGUYENDANG"]);
                GiaiDoanVO.Dat_MB_Roi = Convert.ToInt32(dr["DAT_MB_ROI"]);
                GiaiDoanVO.Dat_MB_Vatlieu = Convert.ToInt32(dr["DAT_MB_VATLIEU"]);
                GiaiDoanVO.Dat_MB_Doam = Convert.ToInt32(dr["DAT_MB_DOAM"]);
                GiaiDoanVO.Dat_MB_Damchat = Convert.ToInt32(dr["Dat_MB_Damchat"]);
                GiaiDoanVO.Dat_MKXB_Nguyendang = Convert.ToInt32(dr["DAT_MKXB_NGUYENDANG"]);
                GiaiDoanVO.Dat_MKXB_Roi = Convert.ToInt32(dr["DAT_MKXB_ROI"]);
                GiaiDoanVO.Dat_MKXB_Vatlieu = Convert.ToInt32(dr["DAT_MKXB_VATLIEU"]);
                GiaiDoanVO.Dat_MKXB_Doam = Convert.ToInt32(dr["DAT_MKXB_DOAM"]);
                GiaiDoanVO.Dat_MKXB_Damchat = Convert.ToInt32(dr["Dat_MKXB_Damchat"]);
                GiaiDoanVO.Da_MT_Coly = Convert.ToInt32(dr["DA_MT_COLY"]);
                GiaiDoanVO.Da_MT_Vatlieu = Convert.ToInt32(dr["DA_MT_VALIEU"]);
                GiaiDoanVO.Da_MB_Coly = Convert.ToInt32(dr["DA_MB_COLY"]);
                GiaiDoanVO.Da_MB_Vatlieu = Convert.ToInt32(dr["DA_MB_VALIEU"]);
                GiaiDoanVO.Da_MKXB_Coly = Convert.ToInt32(dr["DA_MKXB_COLY"]);
                GiaiDoanVO.Da_MKXB_Vatlieu = Convert.ToInt32(dr["DA_MKXB_VALIEU"]);
                GiaiDoanVO.Cat_MT_Catnen = Convert.ToInt32(dr["CAT_MT_CATNEN"]);
                GiaiDoanVO.Cat_MT_Vatlieu = Convert.ToInt32(dr["CAT_MT_VALIEU"]);
                GiaiDoanVO.Cat_MB_Catnen = Convert.ToInt32(dr["CAT_MB_CATNEN"]);
                GiaiDoanVO.Cat_MB_Vatlieu = Convert.ToInt32(dr["CAT_MB_VALIEU"]);
                GiaiDoanVO.Cat_MKXB_Catnen = Convert.ToInt32(dr["CAT_MKXB_CATNEN"]);
                GiaiDoanVO.Cat_MKXB_Vatlieu = Convert.ToInt32(dr["CAT_MKXB_VATLIEU"]);
                GiaiDoanVO.Nuoc_MT_Betong  = Convert.ToInt32(dr["NUOC_MT_BETONG"]);
                GiaiDoanVO.Nuoc_MT_Visinh  = Convert.ToInt32(dr["NUOC_MT_VISINH"]);
                GiaiDoanVO.Nuoc_MB_Betong  = Convert.ToInt32(dr["NUOC_MB_BETONG"]);
                GiaiDoanVO.Nuoc_MB_Visinh  = Convert.ToInt32(dr["NUOC_MB_VISINH"]);
                GiaiDoanVO.Nuoc_MKXB_Betong  = Convert.ToInt32(dr["NUOC_MKXB_BETONG"]);
                GiaiDoanVO.Nuoc_MKXB_Visinh  = Convert.ToInt32(dr["NUOC_MKXB_VISINH"]);
                GiaiDoanVO.Thachhoc_MT  = Convert.ToInt32(dr["THACHHOC_MT"]);
                GiaiDoanVO.Thachhoc_MB  = Convert.ToInt32(dr["THACHHOC_MB"]);
                GiaiDoanVO.Thachhoc_MKXB  = Convert.ToInt32(dr["THACHHOC_MKXB"]);
                GiaiDoanVO.Thuyvan_MT  = Convert.ToInt32(dr["THUYVAN_MT"]);
                GiaiDoanVO.Thuyvan_MB  = Convert.ToInt32(dr["THUYVAN_MB"]);
                GiaiDoanVO.Thuyvan_MKXB  = Convert.ToInt32(dr["THUYVAN_MKXB"]);

                GiaiDoanVO.Cong_MT_Tronggio   = Convert.ToDouble(dr["CONG_MT_TRONGGIO"]);
                GiaiDoanVO.Cong_MT_Ngoaigio = Convert.ToDouble(dr["CONG_MT_NGOAIGIO"]);
                GiaiDoanVO.Cong_MB_Boc = Convert.ToDouble(dr["CONG_MB_BOC"]);
                GiaiDoanVO.Cong_MB_ISO = Convert.ToDouble(dr["CONG_MB_ISO"]);
                GiaiDoanVO.Cong_Nhanuoc = Convert.ToDouble(dr["CONG_NHANUOC"]);

                GiaiDoanVO.NSThiNghiem = Convert.ToDouble(dr["NSTHINGHIEM"]);
                GiaiDoanVO.NSThamChieu  = Convert.ToDouble(dr["NSTHAMCHIEU"]);
                GiaiDoanVO.NSBQ = Convert.ToDouble(dr["NSBQ"]);

                dataTable = GiaiDoanDAO.SearchGiaiDoanDetailByKeySLGiaiDoan(GiaiDoanVO.KeySL);
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    GiaiDoandetailVO = new GiaiDoanDetailVO();
                    GiaiDoandetailVO.KeySL = dataRow["KEYSL"].ToString();
                    GiaiDoandetailVO.KeySLGiaiDoan = dataRow["KeySLGiaiDoan"].ToString();
                    GiaiDoandetailVO.KeySLMauVatLieu = dataRow["KeySLMauVatLieu"].ToString();
                    GiaiDoandetailVO.KeySLThiNghiem = dataRow["KeySLThiNghiem"].ToString();
                    GiaiDoandetailVO.KeySLVatLieu = dataRow["KeySLVatLieu"].ToString();
                    GiaiDoanVO.LstGiaiDoanDetail.Add(GiaiDoandetailVO);
                }
                dataTable = GiaiDoanDAO.SearchNguoiThucHienByKeySLGiaiDoan(GiaiDoanVO.KeySL);
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    GiaiDoannguoithuchienVO = new GiaiDoanNguoiThucHienVO();
                    GiaiDoannguoithuchienVO.KeySL = dataRow["KEYSL"].ToString();
                    GiaiDoannguoithuchienVO.KeySLGiaiDoan = dataRow["KeySLGiaiDoan"].ToString();
                    GiaiDoannguoithuchienVO.ThucHien  = dataRow["THUCHIEN"].ToString();
                    GiaiDoannguoithuchienVO.ThiNghiem = dataRow["THINGHIEM"].ToString();
                    GiaiDoannguoithuchienVO.KetQua = dataRow["KETQUA"].ToString();
                    GiaiDoanVO.LstGiaDoanNguoiThucHien.Add(GiaiDoannguoithuchienVO);
                }


                return GiaiDoanVO;

            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="tenGiaiDoan"></param>
            /// <returns></returns>
            public GiaiDoanVO GetGiaiDoanByKEYSL(string keysl)
            {
                GiaiDoanVO GiaiDoanVO = new GiaiDoanVO();
                DataTable dataTable = new DataTable();
                dataTable = GiaiDoanDAO.SearchByKEYSL(keysl);
                foreach (DataRow dr in dataTable.Rows)
                {
                    GiaiDoanVO = SetGiaiDoan(dr);
                }
                return GiaiDoanVO;
            }
            public GiaiDoanVO InsertRecord(GiaiDoanVO GiaiDoanVO)
            {
                return GiaiDoanDAO.InsertRecord(GiaiDoanVO);
            }
            public bool UpdateRecord(GiaiDoanVO GiaiDoanVO)
            {
                return GiaiDoanDAO.UpdateRecord(GiaiDoanVO);
            }
            public bool DeleteRecord(string keySL)
            {
                return GiaiDoanDAO.DeleteRecord(keySL);
            }
            public DataTable CheckGiaiDoan(string giaidoan, string keySLCongTrinh,string hangmuc)
            {
                return GiaiDoanDAO.CheckGiaiDoan(giaidoan, keySLCongTrinh, hangmuc);
            }
            public List<GiaiDoanVO> GetListGiaiDoan(string condition)
            {
                List<GiaiDoanVO> lstGiaiDoan = new List<GiaiDoanVO>();
                DataTable dataTable = new DataTable();
                dataTable = GiaiDoanDAO.Search(condition);
                foreach (DataRow dr in dataTable.Rows)
                {
                    
                    lstGiaiDoan.Add(SetGiaiDoan(dr));

                }
                return lstGiaiDoan;
            }
            public List<GiaiDoanVO> GetListGiaiDoan()
            {
                List<GiaiDoanVO> lstGiaiDoan = new List<GiaiDoanVO>();
                DataTable dataTable = new DataTable();
                dataTable = GiaiDoanDAO.SearchAll();
                foreach (DataRow dr in dataTable.Rows)
                {
                    lstGiaiDoan.Add(SetGiaiDoan(dr));

                }
                return lstGiaiDoan;
            }
    }
}
